MongoDB Basics

3 minute read

Table Of Contents

The MongoDB University Course M-001 MongoDB Basics is an excellent course, I suggest everyone to Start studying MongoDB with M001. This note doesn’t list out all the details. It’s just listing some important points to remember.

To dump or to export?

To export the data from MongoDB there are two options, mongodump and mongoexport. Here is the list of questionnaire that will help us to take the decision of using the tool.

For this exercise it’s assumed that Source will always be MongoDB

D r s _ e e o _ s a u _ t d r _ i c _ U n ` e _ s D i _ a b _ e e s _ t s i _ s _ i o n _ m t M _ o n d _ o i o _ _ n ` i _ n n n _ c _ g a g _ n _ I o e _ n o t o _ o _ m r s _ o e i d _ _ p _ x o b _ _ o r _ p n ? _ _ r e _ o _ t q _ r _ e u _ t _ y _ r i _ _ e _ r _ _ s _ e _ _ _ s _ _ _ _ _ _ y _ _ e _ _ s _ _ U _ s _ e _ _ m _ o _ n _ g _ o _ d _ u _ m _ p _ U s e m o n g o d u m p

Other notes

  • When using comparision operators, syntax should be {fieldName:{$OP:value}}.
  • When using logic operators. $and, $or and $nor follows this syntax {$OP:[{field:value},{field:value}]}. - When using $not. Syntax should be {$not:{field:value}}
  • When using aggregation operators or expr, syntax should be {$OP:["$field",value]}
  • $elemMatch: The array operator which can be used in query and projection. - If used in query, it only includes those documents where atleast one element in given array matches the given condition. - If used in projection, it only shows those elements in given array that satisfies the given condition.

MongoDB Upsert

In MongoDB, Update Operations are done with following syntax db.collection.update({Query},{UpdateOperation}). By default it will only update the matched document. But there is another clause which allows upsert, if in update syntax we add {upsert:true} as third argument, it will insert the data noted by UpdateOperation if there are no documents matched by Query criteria.


Course

- M-001     

Tags

- M-001